<template>
     <h2 style="text-align: center;">用户还款添加</h2>
     <table>
        <tr>
            <td>借款项目名称</td>
            <td>{{info.B_Name }}</td>
        </tr>
        <tr>
            <td>借款金额</td>
            <td>{{info.UB_Money}}</td>
        </tr>
        <tr>
            <td>借款利息</td>
            <td>{{info.I_Interest}}</td>
        </tr>
        <tr>
            <td>还款金额</td>
            <td><input type="text" v-model="UBMoney"></td>
        </tr>
        <tr>
            <td colspan="2" style="text-align: center;">
             <input type="button" value="提交" @click="SaveData">
            </td>
        </tr>
     </table>
</template>
<script setup lang="ts">
import {ref,onMounted} from 'vue'
import axios from 'axios'
import {useRoute,useRouter} from 'vue-router'

const route = useRoute();

const router = useRouter();


const  info = ref({
    B_Name:"",
    UB_Money:0,
    I_Interest:0
})

onMounted(()=>{
    LoadData()
})

//显示数据
const LoadData = ()=>{

axios("https://localhost:44354/api/Borrows/ShowUserBorrowRedeemInfo",{
   params:{
       UBid:route.params.UBid
   }
}).then(res=>{
  info.value= res.data[0];
}).catch(err=>{
   console.log(err);
})
}

const UBMoney = ref("");
const SaveData =()=>{
    axios({
        url:"https://localhost:44354/api/Borrows/AddUserBorrowRedeemInfo",
        method:"post",
        data:{
            UB_Id:route.params.UBid,
            UBR_Money:UBMoney.value
        }
      }).then((res)=>{
           if(res.data>0)
           {
            alert('还款成功!')
            router.push('/ShowUserBorrowRedeemInfo')
           }
           else
           {
            alert('还款失败!')
           }
      }).catch((err)=>{
        console.log(err);
      })
}
</script>